package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-04-30 11:10
 */
public class Solution_0053 {
    /**
     * 子序列的最大和
     * 以i结尾的
     * f(i)=max{f(i−1)+nums[i],nums[i]}
     *
     * @param nums
     * @return
     */
    public int maxSubArray(int[] nums) {
        int[] res = new int[nums.length+1];
        res[0] = 0;
        for (int i = 0; i < nums.length; i++) {
            res[i+1] = Math.max(res[i] + nums[i], nums[i]);
        }

        return res[res.length - 1];
    }
}
